import matplotlib.pyplot as plt
import numpy as np

import os
path = os.path.dirname(__file__) # 先找到当前文件 a.py 所在的目录
file_name1 = os.path.join(path,'E_point1_1.txt') # 拼接文件的路径
file_name2 = os.path.join(path,'E_Point1_2.txt')
file_name3 = os.path.join(path,'E_Point2_1.txt')
file_name4 = os.path.join(path,'E_Point2_2.txt')
file_name5 = os.path.join(path,'E_Point3_1.txt')
file_name6 = os.path.join(path,'E_Point3_2.txt')
a1 = []
b1 = []
file1 = open(file_name1, mode = 'r')
for line in file1:
    line = line.split()
    a1.append(line)
file1.close()
a11 = []
for m in a1:
    a11.append(float(m[0]))
a1 = a11
file2 = open(file_name2, mode = 'r')
for line in file2:
    line = line.split()
    b1.append(line)
file2.close()
b11 = []
for m in b1:
    b11.append(float(m[0]))
b1 = b11
n11 = len(a1)
n12 = len(b1)
plt.plot(a1[0:n11//2],a1[n11//2:n11],label='n=10',color='r')
plt.plot(b1[0:n12//2],b1[n12//2:n12],'r')
plt.plot([-l for l in a1[0:n11//2]],a1[n11//2:n11],'r')
plt.plot([-l for l in b1[0:n12//2]],b1[n12//2:n12],'r')

a2 = []
b2 = []
file3 = open(file_name3, mode = 'r')
for line in file3:
    line = line.split()
    a2.append(line)
file3.close()
a11 = []
for m in a2:
    a11.append(float(m[0]))
a2 = a11
file4 = open(file_name4, mode = 'r')
for line in file4:
    line = line.split()
    b2.append(line)
file4.close()
b11 = []
for m in b2:
    b11.append(float(m[0]))
b2 = b11
n21 = len(a2)
n22 = len(b2)
plt.plot(a2[0:n21//2],a2[n21//2:n21],label='n=40',color='g')
plt.plot(b2[0:n22//2],b2[n22//2:n22],'g')
plt.plot([-l for l in a2[0:n21//2]],a2[n21//2:n21],'g')
plt.plot([-l for l in b2[0:n22//2]],b2[n22//2:n22],'g')

a3 = []
b3 = []
file5 = open(file_name5, mode = 'r')
for line in file5:
    line = line.split()
    a3.append(line)
file5.close()
a11 = []
for m in a3:
    a11.append(float(m[0]))
a3 = a11
file6 = open(file_name6, mode = 'r')
for line in file6:
    line = line.split()
    b3.append(line)
file6.close()
b11 = []
for m in b3:
    b11.append(float(m[0]))
b3 = b11
n31 = len(a3)
n32 = len(b3)
plt.plot(a3[0:n31//2],a3[n31//2:n31],label='n=160',color='b')
plt.plot(b3[0:n32//2],b3[n32//2:n32],'b')
plt.plot([-l for l in a3[0:n31//2]],a3[n31//2:n31],'b')
plt.plot([-l for l in b3[0:n32//2]],b3[n32//2:n32],'b')
plt.legend()
plt.savefig(os.path.join(path,"figure/E.png"))

plt.figure(2)
plt.plot(a1[0:n11//2],a1[n11//2:n11],label='n=10',color='r')
plt.plot(b1[0:n12//2],b1[n12//2:n12],'r')
plt.plot([-l for l in a1[0:n11//2]],a1[n11//2:n11],'r')
plt.plot([-l for l in b1[0:n12//2]],b1[n12//2:n12],'r')
plt.legend()
plt.savefig(os.path.join(path,"figure/E1.png"))

plt.figure(3)
plt.plot(a2[0:n21//2],a2[n21//2:n21],label='n=40',color='g')
plt.plot(b2[0:n22//2],b2[n22//2:n22],'g')
plt.plot([-l for l in a2[0:n21//2]],a2[n21//2:n21],'g')
plt.plot([-l for l in b2[0:n22//2]],b2[n22//2:n22],'g')
plt.legend()
plt.savefig(os.path.join(path,"figure/E2.png"))

plt.figure(4)
plt.plot(a3[0:n31//2],a3[n31//2:n31],label='n=160',color='b')
plt.plot(b3[0:n32//2],b3[n32//2:n32],'b')
plt.plot([-l for l in a3[0:n31//2]],a3[n31//2:n31],'b')
plt.plot([-l for l in b3[0:n32//2]],b3[n32//2:n32],'b')
plt.legend()
plt.savefig(os.path.join(path,"figure/E3.png"))